const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;

// 基础路由测试
app.get('/', (req, res) => {
  res.send('Server is running');
});

// 添加一个示例API路由
app.post('/users', (req, res) => {
  res.json({ message: 'Test API is working' });
});

// GET /users 路由
app.get('/users', (req, res) => {
  const user = {
    name: "John Doe",
    email: "john@example.com",
    age: 30
  };
  res.json(user); // 返回预期的 JSON 数据
});

app.get('/api/weather', (req, res) => {
  const { city, units, lang } = req.query;

  if (!city) {
    return res.status(400).json({ error: 'City parameter is required' });
  }

  const weatherData = {
    city,
    temperature: 25, // 示例温度
    units,
    lang,
  };

  res.json(weatherData);
});



// 处理未定义的路由
app.use((req, res, next) => {
  res.status(404).json({ error: 'Route not found' });
});
// 启动服务器
app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});